
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TrainingsApp.Model;
using TrainingsApp.Helper;
using WisDragon.Framework.Data.DataAccess;

namespace TrainingsApp.DAL {
    public class TS_School_DAL {
        public static TS_School_Collecion TS_School_ListByPaging(int pageSize, int pageIndex) {
            TS_School_Collecion list = new TS_School_Collecion();
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_ListByPaging");
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_School_Entity> pageList = cmd.ExecuteEntityList<TS_School_Entity>();
                list.TS_School_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return list;

        }


        public static TS_School_Collecion TS_School_ListToGridByPaging(int pageSize, int pageIndex, string where) {
            TS_School_Collecion list = new TS_School_Collecion();
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_ListToGridByPaging");
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                cmd.SetParameterValue("@where", where);
                List<TS_School_Entity> pageList = cmd.ExecuteEntityList<TS_School_Entity>();
                list.TS_School_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return list;

        }

        public static List<TS_School_Entity> TS_School_ListBySearch(string searchText) {

            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_ListBySearch");
                cmd.SetParameterValue("@search", searchText);

                return cmd.ExecuteEntityList<TS_School_Entity>();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_School_Entity>(0);
        }

        public static TS_School_Entity TS_School_View(System.Int64 Idx) {
            TS_School_Entity c = default(TS_School_Entity);
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_View");
                cmd.SetParameterValue("@Idx", Idx);
                c = cmd.ExecuteEntity<TS_School_Entity>();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_School_Entity TS_School_Add(TS_School_Entity entity) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_Add");
                cmd.SetParameterValue("@SchoolCode", entity.SchoolCode);
                cmd.SetParameterValue("@SchoolType", entity.SchoolType);
                cmd.SetParameterValue("@SchoolName", entity.SchoolName);
                cmd.SetParameterValue("@ProvinceId", entity.ProvinceId);
                cmd.SetParameterValue("@AreaId", entity.AreaId);
                cmd.SetParameterValue("@RegionId", entity.RegionId);
                cmd.SetParameterValue("@TownId", entity.TownId);
                cmd.SetParameterValue("@Address", entity.Address);
                cmd.SetParameterValue("@IsValid", entity.IsValid);
                cmd.SetParameterValue("@ZipCode", entity.ZipCode);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return entity;
        }

        public static void TS_School_Update(TS_School_Entity entity) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_Update");
                cmd.SetParameterValue("@Idx", entity.Idx);
                cmd.SetParameterValue("@SchoolCode", entity.SchoolCode);
                cmd.SetParameterValue("@SchoolType", entity.SchoolType);
                cmd.SetParameterValue("@SchoolName", entity.SchoolName);
                cmd.SetParameterValue("@ProvinceId", entity.ProvinceId);
                cmd.SetParameterValue("@AreaId", entity.AreaId);
                cmd.SetParameterValue("@RegionId", entity.RegionId);
                cmd.SetParameterValue("@TownId", entity.TownId);
                cmd.SetParameterValue("@Address", entity.Address);
                cmd.SetParameterValue("@IsValid", entity.IsValid);
                cmd.SetParameterValue("@ZipCode", entity.ZipCode);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
        }

        public static void TS_School_Delete(System.Int64 Idx) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_Delete");
                cmd.SetParameterValue("@Idx", Idx);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
        }

        public static List<TS_School_Entity> TS_School_ListByWhere(int provice, int area, int region) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_School_ListByWhere");
                cmd.SetParameterValue("@ProvinceId", provice);
                cmd.SetParameterValue("@AreaId", area);
                cmd.SetParameterValue("@RegionId", region);

                return cmd.ExecuteEntityList<TS_School_Entity>();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_School_Entity>(0);
        }

    }
}
